<?php
namespace app\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use yii\web\Response;
use app\modules\v1\models\Merchantextrastuff;
use yii\base\Exception;

class DelpictureController extends ActiveController
{
	
    public $modelClass = 'app\modules\v1\models\delpicture';
    
    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'], $actions['update'], $actions['create'], $actions['delete'], $actions['view']);
        return $actions;
    }

    public function actionCreate()
    {
    	$res = array();
    	if(Yii::$app->request->isPost){
    		$openid  = isset(Yii::$app->request->post()['openid'])?Yii::$app->request->post()['openid']:'';
    		$pid  = isset(Yii::$app->request->post()['pid'])?Yii::$app->request->post()['pid']:'';
    		if(empty($openid) || empty($pid)){
    			$res['code'] = '10402';
    			$res['msg']  = '请取消关注后重新关注公众号';
    			$response=Yii::$app->response;
    			$response->format=Response::FORMAT_JSON;
    			$response->data=$res;
    			return $response;
    		}
    		try {
    			$weixininfo = Merchantextrastuff::findOne(['id'=>$pid]);
    			$weixininfo->state = 1;
    			$weixininfo->update();
    			$res['code'] = '10000';
    			$res['msg']  = '成功';
    			$response=Yii::$app->response;
    			$response->format=Response::FORMAT_JSON;
    			$response->data=$res;
    		}catch (Exception $e){
    			$res['code'] = '10400';
    			$res['msg']  = '失败';
    			$response=Yii::$app->response;
    			$response->format=Response::FORMAT_JSON;
    			$response->data=$res;
    		}
    	}else{
    		$res['code'] = '10402';
    		$res['msg']  = '用户太多，请稍后。';
    		$response=Yii::$app->response;
    		$response->format=Response::FORMAT_JSON;
    		$response->data=$res;
    	} 
    }

}